package cn.kgc.itrip.service.ailPayService;

import cn.kgc.itrip.mapper.itripHotelOrder.ItripHotelOrderMapper;
import cn.kgc.itrip.mapper.itripTradeEnds.ItripTradeEndsMapper;
import cn.kgc.itrip.pojo.ItripHotelOrder;
import cn.kgc.itrip.pojo.ItripTradeEnds;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: love_travel
 * @description: 实现
 * @author: Mr.Wang
 * @create: 2020-04-06 16:13
 **/

@Service
public class AliPayServiceImpl implements AliPayService{


    @Resource
    private ItripHotelOrderMapper itripHotelOrderMapper;
    @Resource
    private ItripTradeEndsMapper itripTradeEndsMapper;

    /**
     * 支付前确定信息的展示
     * @param orderNo
     * @return
     */
    @Override
    public ItripHotelOrder findItripOrderByOrderNo(String orderNo) throws Exception{
        Map param = new HashMap();
        param.put("orderNo",orderNo);
        List<ItripHotelOrder> orders = itripHotelOrderMapper.getItripHotelOrderListByMap(param);
        if(orders ==null || orders.size() !=1){
            throw new Exception("数据查询异常");
        }
        return orders.get(0);
    }


    /**
     * 更新订单状态
     * @param order
     * @throws Exception
     */
    @Override
    public void updateOrderStatus(ItripHotelOrder order) throws Exception {
        ItripTradeEnds ends = new ItripTradeEnds();
        ends.setFlag(0);
        ends.setId(order.getId());
        ends.setOrderNo(order.getOrderNo());
        itripTradeEndsMapper.insertItripTradeEnds(ends);
        order.setModifyDate(new Date());
        itripHotelOrderMapper.updateItripHotelOrder(order);
    }

}
